{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**5. Longest Palindromic Substring**  <font color=#f0ad4e size=3>_medium_</font>\n",
    "\n",
    "Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.\n",
    "\n",
    "**Example 1**\n",
    "\n",
    "```\n",
    "Input: \"babad\"\n",
    "Output: \"bab\"\n",
    "Note: \"aba\" is also a valid answer.\n",
    "```\n",
    "\n",
    "**Example 2**\n",
    "\n",
    "```\n",
    "Input: \"cbbd\"\n",
    "Output: \"bb\"\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "aba\n"
     ]
    }
   ],
   "source": [
    "def longestPalindrome(s):\n",
    "    \"\"\"\n",
    "    O(n**3)\n",
    "    \"\"\"\n",
    "    max_lengh = 0\n",
    "    max_seq = \"\"\n",
    "    for i, char in enumerate(s):\n",
    "        for j in range(i, s.__len__()):\n",
    "            substring = s[i:j+1]\n",
    "            if substring == substring[::-1]:\n",
    "                if substring.__len__() > max_lengh:\n",
    "                    max_lengh = substring.__len__()\n",
    "                    max_seq = substring\n",
    "\n",
    "    return max_seq\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    print(longestPalindrome(\"abacde\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
